package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.NursingProjectDto;
import com.zzyl.entity.NursingProject;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import io.swagger.v3.oas.annotations.parameters.RequestBody;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * ClassName: NursingProjectController
 * Package: com.zzyl.controller
 * Description:
 *
 * @Author 贺亚泽
 * @Create 2024/6/6 下午12:04
 * @Version 1.0
 */
@RestController
@RequestMapping("/nursing_project")
@Api(tags = "护理项目管理")
public class NursingProjectController extends BaseController {

    @Autowired
    private NursingProjectService nursingProjectService;


    @GetMapping
    @ApiOperation("分页查询护理项目列表")
    public ResponseResult<PageResponse<NursingProjectVo>> getNursingProByPage( @ApiParam(value = "护理项目名称")String name,
                                                                               @ApiParam(value = "当前页码")Integer pageNum,
                                                                               @ApiParam(value = "每页显示数量")Integer pageSize,
                                                                               @ApiParam(value = "状态：0-禁用，1-启用")Integer status
                                              ) {
        PageResponse<NursingProjectVo> list = nursingProjectService.getByPage(name,pageNum,pageSize,status);
        return ResponseResult.success(list);
    }

    @PostMapping
    @ApiOperation("添加护理项目")
    public ResponseResult addNursingProject(@RequestBody NursingProjectDto nursingProjectDto) {
        nursingProjectService.add(nursingProjectDto);
        return success();
    }

    @GetMapping("/{id}")
    @ApiOperation("根据ID查询护理项目")
    public ResponseResult<NursingProjectVo> getById(@PathVariable Long id){
        NursingProjectVo nursingProjectVo = nursingProjectService.getById(id);
        return success(nursingProjectVo);
    }


    @PutMapping
    @ApiOperation("根据数据更新护理项目")
    public ResponseResult<NursingProjectVo> updateNursingProject(@RequestBody NursingProjectDto nursingProjectDto) {
        nursingProjectService.update(nursingProjectDto);
        return success();
    }

    @PutMapping("/{id}/status/{status}")
    @ApiOperation("启用/禁用功能")
    public ResponseResult updateNursingProjectStatus(@PathVariable Long id, @PathVariable Integer status) {
        nursingProjectService.updateStatus(id,status);
        return success();
    }

    @DeleteMapping("/{id}")
    @ApiOperation("删除功能")
    public ResponseResult deleteNursingProject(@PathVariable Long id) {
        nursingProjectService.delete(id);
        return success();
    }

    @GetMapping("/all")
    @ApiOperation("查询全部")
    public ResponseResult getAllNursingProject() {
        List<NursingProjectVo> list = nursingProjectService.getAll();
        return success(list);
    }
}
